package ar.com.equis.mmInstitucionalWeb.bean {
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.collections.ArrayCollection;
	import mx.collections.IList;
	
	[Bindable]
	public class ModelLocator extends EventDispatcher {
		
		private static var _INSTANCE:ModelLocator;
		private var _products:IList;
		
		public static function get INSTANCE():ModelLocator {
			if(_INSTANCE == null) {
				_INSTANCE = new ModelLocator();
			}
			return _INSTANCE;
		}
		
		public function ModelLocator(target:IEventDispatcher=null) {
			super(target);
		}
		
		public function get products():IList {
			if(_products == null) {
				_products = new ArrayCollection();
			}
			return _products;
		}
		
		public function getProductsBy(category:ProductType):IList {
			var productsByCategory:IList = new ArrayCollection();
			for each(var product:Product in products.toArray()){
				if(product.category == category){
					productsByCategory.addItem(product);
				}
			}
			return productsByCategory;
		}
	}
}